package com.oceansoft.mobile.biz.api.service;

import java.sql.ResultSet;
import java.sql.SQLDataException;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import com.mysql.jdbc.SQLError;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.oceansoft.mobile.biz.api.entity.WxDict;
import com.oceansoft.mobile.common.dao.ICommonDao;
@Service
public class ApiWxDictServiceImpl implements IApiWxDictService{
	@Resource
	private ICommonDao commonDao;

	@Override
	public List<WxDict> getByParentId(int id){
		String sql="select * from t_sys_dict where parentid = ? order by ordernum";
		System.out.print("========sql===="+sql);
		try {
			List<WxDict> list=commonDao.loadList(sql, new RowMapper<WxDict>() {
				@Override
				public WxDict mapRow(ResultSet set, int rownum) throws SQLException {
					WxDict dict=new WxDict();
					dict.setCode(set.getString("code"));
					dict.setDbid(set.getInt("dbid"));
					dict.setDeep(set.getInt("deep"));
					dict.setName(set.getString("name"));
					dict.setOrdernum(set.getInt("ordernum"));
					dict.setParentid(set.getInt("parentid"));
					dict.setParentname(set.getString("parentname"));
					return dict;
				}
			}, id);
			return list;
		}catch (Exception e){
			e.printStackTrace();
			System.out.print("======+++++++++"+e.getMessage());
		}
		System.out.print("=======null");
		return null;
	}

	@Override
	public WxDict getYwms(String casename){
		String sql="select * from t_sys_dict where name ='"+casename+"' and deep=2";
		WxDict list=commonDao.loadOne(sql,WxDict.getservice());
		return list;
	}
}
